package sv.com.renacempleo.web.controller.ctg;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.tuckey.web.filters.urlrewrite.utils.StringUtils;

import sv.com.renacempleo.exception.WebException;
import sv.com.renacempleo.web.controller.BaseController;
import sv.com.renacempleo.web.util.DBContext;
import sv.com.renacempleo.web.util.WebUtilidades;

@Controller
@RequestMapping("/admin/empleado")
public class CtgEmpleadoController extends BaseController{

	private static final long serialVersionUID = -1400605959996167486L;
	
	@RequestMapping(value = "view", method = {RequestMethod.POST})
	public String view(ModelMap model, 
			@RequestParam (required = false) String header) {
		model.addAttribute(WebUtilidades.HEADER_TITLE, StringUtils.isBlank(header) ? "EMPLEADOS" : header);
		try {
			model.put("data", JSONArray.fromObject(DBContext.getCtgEmpleadoDao().findAllAsArray()));
		} catch (WebException e) {
			logger.error("view", e);
		}
		return "admin/catalogo/ctgEmpleado";
	}

}
